<%--
    Document   : registerUser
    Created on : Jul 14, 2011, 5:31:57 PM
    Author     : northpole
--%>

<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <jsp:useBean id="userInfo" scope="page" class="user.User" />
        <%
        String name,surname,dateOfBirth,welcomeText;
        String interests;

        name=request.getParameter("name");
        surname=request.getParameter("surname");

          interests="";
        for(int i=0;i<9;i++)
            {if(request.getParameter("interests"+i)!=null&&!request.getParameter("interests"+i).isEmpty())
        interests=interests+request.getParameter("interests"+i)+",";
        }
          if(request.getParameter("interests10")!=null&&!request.getParameter("interests10").isEmpty())
        interests=interests+request.getParameter("interests10");


        dateOfBirth=request.getParameter("dateOfBirth");
        welcomeText=request.getParameter("welcomeText");

        userInfo.setAll(name, surname,interests,dateOfBirth, welcomeText);
        userInfo.setUsername(request.getParameter("username"));
        userInfo.setPassword(request.getParameter("password"));

        out.println(request.getParameter("password <br>"));

        ArrayList ints=new ArrayList();
        String x="koko";
        if(userInfo!=null)
        x=userInfo.Register();
        if(x ==null||x.isEmpty())
            {out.write("X is Null!!! or empty");}

        String redirectURL ="register.jsp?username="+request.getParameter("username")
                +"&passwrod="+request.getParameter("password")
                + "&name="+request.getParameter("name")
                +"&surname="+request.getParameter("surname")
                +"&dateOfBirth="+request.getParameter("dateOfBirth")
                +"&welcomeText="+request.getParameter("welcomeText")
                +"&password="+request.getParameter("password");
        for(int i=0;i<10;i++){
        if(request.getParameter("interests"+i)!=null&&!request.getParameter("interests"+i).isEmpty())
            {ints.add(request.getParameter("interests"+i));
               redirectURL=redirectURL+"&interests"+i+"="+ints.get(i);}
        }

        String newUrl=null;
        if(x!=null && x.equals("NeedMoarInfo"))
        {newUrl=redirectURL+"&message=Please-Fill-All-of-The-Boxes";}
        else if(x!=null && x.equals("Username Exists")){
        newUrl=redirectURL+"&message=Username Exists";
        }
        else if(x!=null && x.equals("OK"))
        {newUrl="index.jsp";}
        else
            out.write("<h1>x="+x+"</h1>");

       out.write(newUrl);
      // out.write("</br>"+x+"</br>");
       out.write(redirectURL);
       out.write("</br>"+request.getParameter("username"));
        response.sendRedirect(newUrl);
   %>
    </head>
    <body>

    </body>
</html>
